package pcgen;

public final class ClassUtils 
{
	// returns the class (without the package if any)
	@SuppressWarnings("unchecked")
	public static String getClassName(Class c) 
	{
		String fullyQualifiedClassName = "";
		
		fullyQualifiedClassName = c.getName();
	    int firstChar = fullyQualifiedClassName.lastIndexOf('.') + 1;
	    if (firstChar > 0)
	    	fullyQualifiedClassName = fullyQualifiedClassName.substring(firstChar);
		return fullyQualifiedClassName;
	}
	
	
	// returns package and class name
	@SuppressWarnings("unchecked")
	public static String getClassNameFull(Class c) 
	{
		return c.getName();
	}
	
	// returns the package without the classname, empty string if
	// there is no package
	@SuppressWarnings("unchecked")
	public static String getPackageName(Class c) 
	{
		String fullyQualifiedName = c.getName();
	    int lastDot = fullyQualifiedName.lastIndexOf('.');
	    if (lastDot == -1)
	    	return "";
	    
	    return fullyQualifiedName.substring(0, lastDot);
	}
}
